/***************************************************************************
 创建者：       hualei
 开始时间：    2018.09.10
 copyright:(C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************/

#include "tcpreadinstructiondelegate.h"
#include <QDebug>

TCPReadInstructionDelegate::TCPReadInstructionDelegate(QWidget *parent)
    : QWidget(parent)
{
}

void TCPReadInstructionDelegate::initialView()
{
    tcpReadInstructionView->tcpReadClientIPVec.resize(4);
    tcpReadInstructionView->tcpReadServerIPVec.resize(4);
    tcpReadInstructionView->tcpReadBusType = E_TCP_READ_BUS_CLIENT;
    tcpReadInstructionView->tcpReadPort = 5059;
    tcpReadInstructionView->tcpReadRegBeginAddress = 1;
    tcpReadInstructionView->tcpReadRegLength = 1;
    tcpReadInstructionView->jmpLBValue =1;
    tcpReadInstructionView->noteStr = "No note!";

}

void TCPReadInstructionDelegate::finishEditInstructionSlot()
{
    tcpReadInstructionView->instructionOut = "TCP_READ ";
    tcpReadInstructionView->instructionOut += tr("R[") + QString::number(tcpReadInstructionView->tcpReadRegBeginAddress) + "],";
    tcpReadInstructionView->instructionOut += tr("R[") + QString::number(tcpReadInstructionView->tcpReadRegLength) + "],";

    if(tcpReadInstructionView->tcpReadBusType == E_TCP_READ_BUS_CLIENT)
    {
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadServerIPVec[0]) + ".";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadServerIPVec[1]) + ".";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadServerIPVec[2]) + ".";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadServerIPVec[3]) + ",";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadPort) + ",";
        tcpReadInstructionView->instructionOut += tr("CLIENT") + ",";

    }
    else if(tcpReadInstructionView->tcpReadBusType == E_TCP_READ_BUS_SERVER)
    {
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadClientIPVec[0]) + ".";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadClientIPVec[1]) + ".";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadClientIPVec[2]) + ".";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadClientIPVec[3]) + ",";
        tcpReadInstructionView->instructionOut += QString::number(tcpReadInstructionView->tcpReadPort) + ",";
        tcpReadInstructionView->instructionOut += tr("SERVER") + ",";
    }



    tcpReadInstructionView->instructionOut += tr("JMP ") + tr("LB[") + QString::number(tcpReadInstructionView->jmpLBValue) + "] ";
    tcpReadInstructionView->instructionOut += " //" + tcpReadInstructionView->noteStr;

    qDebug() << "TCPReadInstructionDelegate Instruction = " << tcpReadInstructionView->instructionOut;
}

void TCPReadInstructionDelegate::cleanNoteStrSlot()
{
    tcpReadInstructionView->noteStr.clear();
}

